<%@page import="tr.com.argela.tap.mot.models.User"%>
<%@page import="tr.com.argela.tap.mot.models.Project"%>
<%@page import="tr.com.argela.tap.mot.models.Version"%>
<%@page import="tr.com.argela.tap.mot.dao.ProjectDao"%>
<%@page import="java.util.List"%>
<%@ page import="java.io.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
   
   
   <html>
   
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" type="text/css" href="style/styles.css">
        <script type="text/javascript" src="js/basic.js"></script>
		<script type="text/javascript" src="js/side_menu.js"></script>	
		<!-- calendar libraries  -->
		<script type="text/javascript" src="js/calendar.js"></script>
		<link rel="stylesheet" type="text/css" href="style/calendar-win2k-cold-1.css"/>
		 
		 <script type="text/javascript">
		 
		function selectedProject(component) {
		      
		      		var selectedProject=component.options[component.selectedIndex].value;

                    var functionCombo = document.getElementById('functions');

                    var itemCombo = document.getElementById('items');
		 
		 			 while (functionCombo.firstChild) {

                        functionCombo.removeChild(functionCombo.firstChild);

                    }

                    while (itemCombo.firstChild) {

                        itemCombo.removeChild(itemCombo.firstChild);

                    }
                   
                     addOption(functionCombo, '', '<%//=iLabel.get("option.select")%>' );

                    addOption(itemCombo, '', '<%//=iLabel.get("option.select")%>' );
                    
                     if(selectProject.length==0){

                        clean(component);

                        functionCombo.disabled="disabled";

                        itemCombo.disabled="disabled";

                        return;

                    }
                     var xhr=getPostObject("profileData","page=getFunctions&projectId="+selectedProject);

                     var result=xhr.responseText;

                     if(isErrorOccured(result)) {

                         showError(component, getErrorMessage(result));

                         return;

                     } else {

                         clean(component);

                     }

                     var functionArr=result.split("#");

       

  

       

                     for(var i=0;i<functionArr.length;i++){

                         if(functionArr[i]==""){

                             continue;

                         }

                         var temp=functionArr[i].split(";");

                         if(temp[0]==""){

                             continue;

                         }

                         addOption(functionCombo, temp[0], temp[1] );

                     }

                     functionCombo.disabled="";

  

  

                     var xhr=getPostObject("profileData","page=getItems&projectId="+selectedProject);

                     var result=xhr.responseText;

                     if(isErrorOccured(result)) {

                    	 showError(component, getErrorMessage(result));

                         return;

                     } else {

                         clean(component);

                     }

  ///değiştir

                     if(result=='property_type_date'){

                         document.getElementById('itemTr').style.display="none";

                         document.getElementById('dateTr').style.display="";

                     } else {

                         document.getElementById('itemTr').style.display="";

                         document.getElementById('dateTr').style.display="none";

                         var itemArr=result.split("#");

                         for(var i=0;i<itemArr.length;i++){

                             if(itemArr[i]==""){

                                 continue;

                             }

                     

                             var temp=itemArr[i].split(";");

                             if(temp[0]==""){

                                 continue;

                             }

                             addOption(itemCombo, temp[0], temp[1] );

                         }

                         itemCombo.disabled="";

                     }

  

  

       

                     var xhr=getPostObject("VersionServlet","page=getProjectDetails&projectId="+selectedProject);

                     var result=xhr.responseText;

       

                     if(isErrorOccured(result)) {

                         showError(component, getErrorMessage(result));

                         return;

                     } else {

                         clean(component);

                     }

                     var logicTr = document.getElementById('logicTr');

                     if(result=='true') {

                         logicTr.style.display="";

                     } else {

                         logicTr.style.display="none";

                     }
      
		 }
		 
		
		 </script> 
		</head>
    <%
     User user = (User)request.getSession().getAttribute("userObject");
     String name = user.getName();
     
%>
    <body>
    <h4 align="right">Welcome <%=name%></h4>
    <h5 align="right"><a href="logout.jsp">Log out</a></h5>
       <div  align="center"> <h1 align="center">MOT</h1><h5 align="center">Memory Of Testing</h5></div>
    
        <dıv  align="left">
        <table align="left">
               <tr><td>
	        <h4><a href="currentProjects.jsp">Current Projects</a></h4>
	    </td></tr>
	      <tr><td>
	      	<h4><a href="createProject.jsp">Create Project</a></h4>
	    </td></tr>
	       <tr><td>
	         <h4><a href="projectVersion.jsp">Create Project Version</a></h4>
	    </td></tr>
	      
	        <tr><td>
	          <h4><a href="users.jsp">Users</a></h4>
	    </td></tr>
	        <tr><td>
	           <h4><a href="export.jsp">Export Document</a></h4>
	    </td></tr>
        </table>
        </dıv>
        <form action="VersionServlet">
        <dıv align="right">
         <table border="3" align="center">
    <tr><th colspan="2" align="center"> Create Project Version </th></tr>
    <tr><td >Project </td><td><select name="projects"  id="projects" onchange="javascript: selectedProject(this);">
	  <% 
		ProjectDao proDao = new ProjectDao();
		
		List<Project> projects = proDao.seeProjects();
		
		for (Project project : projects) {
		%> 
		<option value="<%=project.getId()%>" ><%=project.getName()%></option>
		
		<% }
		
	%>
    
	</select></td></tr>
	<tr><td>Version name:</td><td>
	<input type="text" name="vname"></td></tr>
    <tr><td>Description:</td><td>
    <input type="text" name="vdescription"></td></tr>
    <tr><td>Release Date:</td><td>
    <input type="text" name="endDate" id="endDate" maxlength="0" value=""/> 
    <img src="images/calendar.jpeg"  id="endDateButton" class="cal_icon"  onmouseover="       javascript: iconHov(this);"             onmouseout="javascript: iconHout(this);"/>
	<script type="text/javascript">
     Calendar.setup({
           inputField    : "endDate",

           button        : "endDateButton"
     });</script>
     </td></tr>
    <tr><td colspan="2" align="center">
    <input  type="hidden" name="version" id="version" value="createversion"/>
    <input type="submit" name="prover" value="Save">
    <input type="reset" name="cancel" value="Cancel">
    </td></tr>
    </table></dıv>
    </form>
    </body></html>